﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Autofac;
using AutofacContrib.Scriptable;
using System.IO;
using NUnit.Framework;

namespace AutofacContrib.Tests.Scriptable
{
    public interface ITest
    {
        string GetMessage();
    }

    public class Test : ITest
    {
        private string _message;

        public Test()
        {
            _message = "TEST";
        }

        public string GetMessage()
        {
            return _message;
        }
    }


    [TestFixture]
    public class ScriptableBuilderFixture
    {
        [Test]
        public void TestRegisterFromScript()
        {
            var builder = new ContainerBuilder();
            builder.RegisterFromScript(File.ReadAllText("Builder.py"), ScriptEngineType.Python);
            var container = builder.Build();
            var test = container.Resolve<ITest>();
            Assert.AreEqual("PTEST", test.GetMessage());
        }

        [Test]
        public void TestRegisterFromScriptFile()
        {
            var builder = new ContainerBuilder();
            builder.RegisterFromScriptFile("Builder.py", ScriptEngineType.Python);
            var container = builder.Build();
            var test = container.Resolve<ITest>();
            Assert.AreEqual("PTEST", test.GetMessage());
        }
    }
}
